package dev.werillib.widget.recyclerAnimator

import android.view.ViewPropertyAnimator
import androidx.recyclerview.widget.RecyclerView

/**
 * is a sample
 */
class SampleItemAnimator : BaseItemAnimator() {

    override fun setRemoveAnimation(holder: RecyclerView.ViewHolder, animator: ViewPropertyAnimator) {
        holder.itemView.pivotX = (holder.itemView.width / 2).toFloat()
        holder.itemView.pivotY = 0f
        animator.scaleX(0f).scaleY(0f)
        animator.translationY(-holder.itemView.y)
        animator.duration = 600
    }

    override fun removeAnimationEnd(holder: RecyclerView.ViewHolder) {
        holder.itemView.pivotX = (holder.itemView.width / 2).toFloat()
        holder.itemView.pivotY = (holder.itemView.height / 2).toFloat()
        holder.itemView.scaleX = 1f
        holder.itemView.scaleY = 1f
        holder.itemView.translationY = 0f
    }

    override fun addAnimationInit(holder: RecyclerView.ViewHolder) {
        holder.itemView.translationX = 0f
        holder.itemView.translationY = 0f
    }

    override fun setAddAnimation(holder: RecyclerView.ViewHolder, animator: ViewPropertyAnimator) {
        holder.itemView.pivotX = (holder.itemView.width / 2).toFloat()
        holder.itemView.pivotY = (holder.itemView.height / 2).toFloat()
        animator.scaleX(1f).scaleY(1f)
    }

    override fun addAnimationCancel(holder: RecyclerView.ViewHolder) {
        holder.itemView.scaleX = 1f
        holder.itemView.scaleY = 1f
    }

    override fun setOldChangeAnimation(holder: RecyclerView.ViewHolder, animator: ViewPropertyAnimator) {
        holder.itemView.pivotX = (holder.itemView.width / 2).toFloat()
        holder.itemView.pivotY = (holder.itemView.height / 2).toFloat()
        animator.scaleX(0f).scaleY(0f)
    }

    override fun oldChangeAnimationEnd(holder: RecyclerView.ViewHolder?) {
        holder!!.itemView.scaleX = 1f
        holder.itemView.scaleY = 1f
    }

    override fun newChangeAnimationInit(holder: RecyclerView.ViewHolder) {
        holder.itemView.scaleX = 0f
        holder.itemView.scaleY = 0f
    }

    override fun setNewChangeAnimation(holder: RecyclerView.ViewHolder, animator: ViewPropertyAnimator) {
        holder.itemView.pivotX = (holder.itemView.width / 2).toFloat()
        holder.itemView.pivotY = (holder.itemView.height / 2).toFloat()
        animator.scaleX(1f).scaleY(1f)
    }

    override fun newChangeAnimationEnd(holder: RecyclerView.ViewHolder?) {
        holder!!.itemView.scaleX = 1f
        holder.itemView.scaleY = 1f
    }
}
